/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.lottery.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.lottery.entity.WechatActor;
import com.thinkgem.jeesite.modules.lottery.service.WechatActorService;

/**
 * 用户角色管理Controller
 * @author Muser
 * @version 2019-07-31
 */
@Controller
@RequestMapping(value = "${adminPath}/lottery/wechatActor")
public class WechatActorController extends BaseController {

	@Autowired
	private WechatActorService wechatActorService;
	
	@ModelAttribute
	public WechatActor get(@RequestParam(required=false) String id) {
		WechatActor entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = wechatActorService.get(id);
		}
		if (entity == null){
			entity = new WechatActor();
		}
		return entity;
	}
	
	@RequiresPermissions("lottery:wechatActor:view")
	@RequestMapping(value = {"list", ""})
	public String list(WechatActor wechatActor, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<WechatActor> page = wechatActorService.findPage(new Page<WechatActor>(request, response), wechatActor); 
		model.addAttribute("page", page);
		return "modules/lottery/wechatActorList";
	}

	@RequiresPermissions("lottery:wechatActor:view")
	@RequestMapping(value = "form")
	public String form(WechatActor wechatActor, Model model) {
		model.addAttribute("wechatActor", wechatActor);
		return "modules/lottery/wechatActorForm";
	}

	@RequiresPermissions("lottery:wechatActor:edit")
	@RequestMapping(value = "save")
	public String save(WechatActor wechatActor, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, wechatActor)){
			return form(wechatActor, model);
		}
		wechatActorService.save(wechatActor);
		addMessage(redirectAttributes, "保存用户角色成功");
		return "redirect:"+Global.getAdminPath()+"/lottery/wechatActor/?repage";
	}
	
	@RequiresPermissions("lottery:wechatActor:edit")
	@RequestMapping(value = "delete")
	public String delete(WechatActor wechatActor, RedirectAttributes redirectAttributes) {
		wechatActorService.delete(wechatActor);
		addMessage(redirectAttributes, "删除用户角色成功");
		return "redirect:"+Global.getAdminPath()+"/lottery/wechatActor/?repage";
	}

}